
Product
Secure Your AI-Generated Code with Socket MCP
Socket MCP brings real-time security checks to AI-generated code, helping developers catch risky dependencies before they enter the codebase.
rsa-pem-from-mod-exp
Advanced tools
Create RSA Public Key PEM from Modulus and Exponent value in node.js
The rsa-pem-from-mod-exp npm package is used to convert RSA public key components (modulus and exponent) into a PEM formatted string. This is useful for applications that need to handle RSA keys in a standardized format.
Convert RSA modulus and exponent to PEM
This feature allows you to convert RSA public key components (modulus and exponent) into a PEM formatted string. The provided code sample demonstrates how to use the package to achieve this conversion.
const rsaPemFromModExp = require('rsa-pem-from-mod-exp');
const modulus = '00c1b0...'; // Hexadecimal string
const exponent = '010001'; // Hexadecimal string
const pem = rsaPemFromModExp(modulus, exponent);
console.log(pem);
The node-rsa package provides a comprehensive set of tools for working with RSA keys, including key generation, encryption, decryption, and conversion to/from various formats. It offers more functionality compared to rsa-pem-from-mod-exp, which is focused solely on converting modulus and exponent to PEM format.
The pem-jwk package allows for conversion between PEM and JWK (JSON Web Key) formats. While it provides broader functionality in terms of key format conversions, it can also handle the specific task of converting RSA modulus and exponent to PEM, similar to rsa-pem-from-mod-exp.
The node-forge package is a robust library for implementing various cryptographic functions in JavaScript, including RSA key generation, encryption, decryption, and conversion between different key formats. It offers a wider range of cryptographic utilities compared to rsa-pem-from-mod-exp.
Create RSA Public Key PEM from Modulus and Exponent value in node.js. There are no dependencies to other modules for use.
This allows you to use the modulus/exponent values for validating signed value.
The original code is based on the answer to this stackoverflow question.
npm install rsa-pem-from-mod-exp
//getPem = function(modulus_base);
var getPem = require('rsa-pem-from-mod-exp');
//modulus should be a base64/base64Url string
var modulus = "niqcAxl7LclB0kE6q9AcAd8EE+0W6AsriR9Fs9T+6QVXl8uiCiAbh/KCyy8X8C2bHsFpNBvwGTqMwHbqZqWBVUvYRtfCFcy3Xmertb09DnOBeWqKS4181kss97JDO6G07QNbuLSWwkkO82CHD1kUmeF5/dof0Ra6bsRXqppdo86NzlgFud+E2s5BM3XwewZVSpA69bwEiXaRDhrsg5mqeOm68VyxE8LQu+895kKsBnTvTueZTrXT+HNaIveoYe8+Lb7b/mZYtlhrDK0i/8EDox85vxnzKZ7wNswqqcDg6vfC2911phSTPh13jv2FIOkjO/WHhHEzRnS2VQqivqIbsQ";
//exponent should be base64/base64url
var exponent = "AQAB";
var pem = getPem(modulus, exponent);
In the above example pem will now contain the following string.
-----BEGIN RSA PUBLIC KEY-----
MIIBCgKCAQEAniqcAxl7LclB0kE6q9AcAd8EE+0W6AsriR9Fs9T+6QVXl8uiCiAb
h/KCyy8X8C2bHsFpNBvwGTqMwHbqZqWBVUvYRtfCFcy3Xmertb09DnOBeWqKS418
1kss97JDO6G07QNbuLSWwkkO82CHD1kUmeF5/dof0Ra6bsRXqppdo86NzlgFud+E
2s5BM3XwewZVSpA69bwEiXaRDhrsg5mqeOm68VyxE8LQu+895kKsBnTvTueZTrXT
+HNaIveoYe8+Lb7b/mZYtlhrDK0i/8EDox85vxnzKZ7wNswqqcDg6vfC2911phST
Ph13jv2FIOkjO/WHhHEzRnS2VQqivqIbsQIDAQAB
-----END RSA PUBLIC KEY-----
npm test
npm run cover
FAQs
Create RSA Public Key PEM from Modulus and Exponent value in node.js
The npm package rsa-pem-from-mod-exp receives a total of 249,534 weekly downloads. As such, rsa-pem-from-mod-exp popularity was classified as popular.
We found that rsa-pem-from-mod-exp demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket MCP brings real-time security checks to AI-generated code, helping developers catch risky dependencies before they enter the codebase.
Security News
As vulnerability data bottlenecks grow, the federal government is formally investigating NIST’s handling of the National Vulnerability Database.
Research
Security News
Socket’s Threat Research Team has uncovered 60 npm packages using post-install scripts to silently exfiltrate hostnames, IP addresses, DNS servers, and user directories to a Discord-controlled endpoint.